<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.constants.GlobalConstants"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.entity.Request"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.enums.RequestField"%>
<%@page import="ae.pcfc.etks.online.itworx.ehs.web.enums.RequestStatus"%>

<%
		if (session.getAttribute(GlobalConstants.SUCCESS_PARAM) != null) {
	%>
<script type="text/javascript">
				$(document).ready(
								function() {
									jAlert(
											'<%=session.getAttribute(GlobalConstants.SUCCESS_PARAM)%>','',
											'<spring:message code="msg.success" />');
								});
			</script>
<%
	session.removeAttribute(GlobalConstants.SUCCESS_PARAM);
	}
%>

<form:form modelAttribute="<%=GlobalConstants.REQUEST_SEARCH_CRITERIA%>"
	name="searchRequest" id="searchRequest" method="POST"
	action='${(requestSearchCriteria.type eq "inbox") ? "client/viewInbox.htm" : "client/listRequests.htm"}'
	enctype="text/html">

	<div class="error_msg"><spring:bind path="requestSearchCriteria.*"><c:forEach items="${status.errorMessages}" var="error"><c:out value="${error}" /><br /></c:forEach></spring:bind></div>

	<form:hidden path="sortField" />
	<form:hidden path="assending" />
	<form:hidden path="type" id="type" name="type" />
	<table id="tblSearch" class="grdView searchTbl">
		<caption>
			<spring:message code="label.titel.search" />
		</caption>
		<colgroup>
			<col width="22%" />
			<col width="29%" />
			<col width="22%" />
			<col width="20%" />
			<col width="7%" />				
		</colgroup>	
		<tr>
			<td><spring:message code="label.request.requestId" />
			</td>
			<td><form:input path="viewRequestId" type="text" class="srchTxt" />
			</td>
			<td><spring:message code="label.request.status" />
			</td>
			<td colspan="2">
				<form:select path="requestStatus"
					class="fm-opt trade_licence" title="">
					<form:option value="0"><spring:message code="label.request.select"/></form:option>
					<c:forEach items="${requestSearchCriteria.statuses}" var="status">
						<c:set var="statusTitle"><spring:message code="${status.statusName}"/></c:set>
						<form:option value="${status.statusName}" title="${statusTitle}"><spring:message code="${status.statusName}"/></form:option>
					</c:forEach>
				</form:select>
			</td>
		</tr>
		<tr>
			<td><spring:message code="label.request.company.nameeng" />
			</td>
			<td><form:input path="companyNameEn" type="text" class="srchTxt" />
			</td>
			<td><spring:message code="label.request.company.namearab" />
			</td>
			<td colspan="2"><form:input path="companyNameAr" type="text"
					class="srchTxt" />
			</td>
		</tr>
		<tr>
			<spring:message code="label.date.field.chooseDate" var="dateToolTip"/>
			<td><spring:message code="label.request.submissionDate" />
			</td>
			<td>
				<form:input path="submissionDate" type="text"
					size="12" name="date1" id="inputField1" class="t_form-fld-disable_calendar" readonly="true" title="${dateToolTip}"/>
				<img src="resources/images/edit-clear.png" width="16px" height="16px" class="clear_submission_date" title='<spring:message code="label.img.field.removeDate" />'/>
			</td>
			<td><spring:message code="label.request.receivedDate" />
			</td>
			<td style="width: 160px"><form:input path="receivedDate"
					type="text" 
					name="date1"
					size="12" id="inputField2" class="t_form-fld-disable_calendar"  title="${dateToolTip }" readonly="true"/>
				<img src="resources/images/edit-clear.png" width="16px" height="16px" class="clear_recieved_date" title='<spring:message code="label.img.field.removeDate" />'/>
			</td>
			<td>
				<span class="btn_border">
					<button type="button" class="btn_bg" id="searchButton" onclick='document.forms[0].submit();'>
						<spring:message code="label.allRequests.button" />
					</button>
				</span>
			</td>
		</tr>
	</table>

	<div class="brk"></div>
	<c:choose>
		<c:when test="${( requests == null) or (empty requests) }">
			<div class="error_dark"><spring:message code="label.allRequests.noResults" /></div>
		</c:when>
		<c:otherwise>
			<table id="myRequests" class="grdView">
				<caption>
					<c:if test='${(requestSearchCriteria.type eq "inbox")}'>
						<spring:message code="label.menu.inbox" />
					</c:if>
					<c:if test='${(requestSearchCriteria.type eq "myRequests")}'>
						<spring:message code="label.titel.myRequests" />
					</c:if>
					
				</caption>
				<colgroup>
                        <col width="20%" />
                        <col width="30%" />
                        <col width="10%" />
                        <col width="20%" />
                        <col width="10%" />
                        <col width="10%" />
				</colgroup>
				<tr>
					<th>
						<div class="sort_title">
							<a style='cursor: pointer' onclick="doSorting('<%=RequestField.RequestId.getPropertyName()%>');"> <spring:message code="label.request.requestId" /> </a>
							<c:set var="currField" value="<%=RequestField.RequestId.getPropertyName()%>"/>
							<c:if test="${requestSearchCriteria.sortField eq currField }" >
								<c:if test="${requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_up.png"/>
								</c:if>
								<c:if test="${!requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_down.png"/>
								</c:if>
							</c:if>
						</div>
						
					</th>
					<th><a style='cursor: pointer'
						onclick="doSorting('<%=RequestField.CompanyNameEn.getPropertyName()%>');">
							<spring:message code="label.allRequests.companyNameEn-ar" /> </a>
						<c:set var="currField" value="<%=RequestField.CompanyNameEn.getPropertyName()%>"/>
						<c:if test="${requestSearchCriteria.sortField eq currField }" >
								<c:if test="${requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_up.png"/>
								</c:if>
								<c:if test="${!requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_down.png"/>
								</c:if>
							</c:if>
					</th>
					<th><a style='cursor: pointer'
						onclick="doSorting('<%=RequestField.CreationDate.getPropertyName()%>');">
							<spring:message code="label.request.submissionDate" /> </a>
							<c:set var="currField" value="<%=RequestField.CreationDate.getPropertyName()%>"/>
						<c:if test="${requestSearchCriteria.sortField eq currField }" >
								<c:if test="${requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_up.png"/>
								</c:if>
								<c:if test="${!requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_down.png"/>
								</c:if>
							</c:if>
					</th>
					<th><a style='cursor: pointer'
						onclick="doSorting('<%=RequestField.Status.getPropertyName()%>');">
							<spring:message code="label.request.status" /> </a>
							<c:set var="currField" value="<%=RequestField.Status.getPropertyName()%>"/>
						<c:if test="${requestSearchCriteria.sortField eq currField }" >
								<c:if test="${requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_up.png"/>
								</c:if>
								<c:if test="${!requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_down.png"/>
								</c:if>
							</c:if>
					</th>
					<th><a style='cursor: pointer'
						onclick="doSorting('<%=RequestField.ProcessingDate.getPropertyName()%>');">
							<spring:message code="label.request.receivedDate" /> </a>
							<c:set var="currField" value="<%=RequestField.ProcessingDate.getPropertyName()%>"/>
						<c:if test="${requestSearchCriteria.sortField eq currField }" >
								<c:if test="${requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_up.png"/>
								</c:if>
								<c:if test="${!requestSearchCriteria.assending}" >
									<img src="resources/images/arrow_down.png"/>
								</c:if>
							</c:if>
					</th>
					<th><spring:message code="label.request.document.actions" />
					</th>
				</tr>
				<c:forEach var="req" items="${requests}" varStatus="loopStatus">
					<tr ${loopStatus.index % 2 == 0 ? 'class="grdAltRow"' : ''}>
						<td align="center"><a
							href="client/viewDetails.htm?requestId=${req.id}&type=${requestSearchCriteria.type}">
								${req.service.name}_${req.type}_<fmt:formatDate value="${req.creationDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_ID_DATE_FORMAT%>" />_${req.id} </a>
						</td>
						<td>${req.companyNameEnglish}- ${req.companyNameArabic}</td>
						<td><fmt:formatDate value="${req.creationDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_DATE_FORMAT%>"/></td>
						<td><spring:message code="${req.status}" /></td>
						<td><fmt:formatDate value="${req.processingDate}" pattern="<%=GlobalConstants.DEFAULT_VIEW_DATE_FORMAT%>"/></td>
						<td>
							<c:choose>
								<c:when test='${(req.status eq "Submitted") or (req.status eq "Resubmitted") or (req.status eq "Return_For_Update") or (req.status eq "Approved")}'>
									<a style='cursor: pointer'><img
										src="resources/images/common/cancel_icon.png" onclick="showCancelCloseConfirmation('${pageContext.request.contextPath}/client/cancel.htm?requestId=${req.id}&type=${requestSearchCriteria.type}', 'true');" title='<spring:message code="label.img.cancel"/>'/>
									</a>
								</c:when>
							</c:choose>
						</td>
					</tr>
				</c:forEach>
			</table>

			<div class="grdPager">
				<c:if test="${!requestSearchCriteria.firstPage}">

					<a style='cursor: pointer' onclick="doPaginate('1');"> <<
						<spring:message code="label.img.first" /> </a>

					<a style='cursor: pointer'
						onclick="doPaginate('${requestSearchCriteria.pageNumber-1}');">
						< <spring:message code="label.img.prev" /> </a>
				</c:if>
				<span class="label"> <spring:message code="label.list.pageWord" /></span>
				<form:input path="pageNumber" type="text" name="pageIndex"
					id="pageIndex" cssStyle="width:50px;"
					value="${requestSearchCriteria.pageNumber}"
					onkeypress="jumbToPage(event);" />
				<span class="label"> <spring:message code="label.list.ofWord" />
					${requestSearchCriteria.totalPageNumber} </span>
				<c:if
					test="${!requestSearchCriteria.lastPage and requestSearchCriteria.pageNumber < requestSearchCriteria.totalPageNumber}">
					<a style='cursor: pointer'
						onclick="doPaginate('${requestSearchCriteria.pageNumber+1}');">
						<spring:message code="label.img.next" /> > </a>
					<a style='cursor: pointer'
						onclick="doPaginate('${requestSearchCriteria.totalPageNumber}');">
						<spring:message code="label.img.last" /> >> </a>
				</c:if>

			</div>
		</c:otherwise>
	</c:choose>


</form:form>